/*
*  Copyright 2019-2020 Zheng Jie
*
*  Licensed under the Apache License, Version 2.0 (the "License");
*  you may not use this file except in compliance with the License.
*  You may obtain a copy of the License at
*
*  http://www.apache.org/licenses/LICENSE-2.0
*
*  Unless required by applicable law or agreed to in writing, software
*  distributed under the License is distributed on an "AS IS" BASIS,
*  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
*  See the License for the specific language governing permissions and
*  limitations under the License.
*/
package com.mcx.modules.rest;

import com.mcx.modules.domain.Gameserver;
import com.mcx.modules.service.GameserverService;
import com.mcx.modules.service.dto.GameserverQueryCriteria;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/api/gameserver")
public class GameserverController {

    private final GameserverService gameserverService;

    @GetMapping
    public ResponseEntity<Object> query(GameserverQueryCriteria criteria, Pageable pageable){
        return new ResponseEntity<>(gameserverService.queryAll(criteria, pageable),HttpStatus.OK);
    }

    @PostMapping
    public ResponseEntity<Object> create(@Validated @RequestBody Gameserver resources){
        return new ResponseEntity<>(gameserverService.create(resources),HttpStatus.CREATED);
    }

    @PutMapping
    public ResponseEntity<Object> update(@Validated @RequestBody Gameserver resources){
        gameserverService.update(resources);
        return new ResponseEntity<>(HttpStatus.NO_CONTENT);
    }

    @DeleteMapping
    public ResponseEntity<Object> delete(@RequestBody Integer[] ids) {
        gameserverService.deleteAll(ids);
        return new ResponseEntity<>(HttpStatus.OK);
    }

    @GetMapping("/get")
    public ResponseEntity<Object> gameServerPage(Integer id){
        if (id == 0) id = gameserverService.getCount();
        return new ResponseEntity<>(gameserverService.findById(id), HttpStatus.OK);
    }

    @GetMapping("/getPage")
    public ResponseEntity<Object> gameServer(){
        return new ResponseEntity<>(gameserverService.getPage(), HttpStatus.OK);
    }
}